
const app = getApp();
var config = require('../../config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    UserInfo:{},
    DataList:[],
    productName:'',
    imgPath: config.imgPath,
    searchProdut:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.editTabbar();
  },

  onShow: function () {
    let self = this
    app.request({
      url: 'api/wechat/getUserInfo',
      method: "GET",
      success: function (res) {
        self.setData({
          UserInfo: res.data.info
        })
      }
    })
    this.loadDetail();
  },
  loadDetail() {
    let self = this
    app.request({
      url: 'api/UserCenter/getFavorite',
      method: "GET",
      data:{productName:self.data.searchProdut},
      success: function (res) {
        if (res.data != null) {
            self.setData({
              DataList: res.data.productList,
            })
          }
      }
    })
  },
  searchProdutInput(e){
    this.setData({
      searchProdut : e.detail.value
    })
  },
  search:function(){
    this.loadDetail()
  },
  deleteFavorite:function (e) {
    var productId = e.target.dataset.productid
    let self = this
    app.request({
      url: 'api/UserCenter/deleteFavorite',
      method: "GET",
      data:{productId:productId},
      success: function (res) {
        self.loadDetail()
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})